package com.jack.algorithm;


import com.jack.common.exception.Assert;

/**
 * Created by zhang_j on 2020/7/17
 */
public class bubbleSort {

    public static void main(String[] args) {
        int[] a = {9,8,7,6,5,1,2,3};
        bubbleSort(a);
        for (int i : a) {
            System.out.print(i + ",");
        }
    }

    private static void bubbleSort(int[] nums){
        Assert.notNull(nums, "nums is null");
        int n = nums.length;

        for(int i = n - 1;i >= 0;i--){
            for(int j = 0;j < i;j++){
                if(nums[j] > nums[j+1]){
                    int tmp = nums[j];
                    nums[j] = nums[j+1];
                    nums[j+1] = tmp;
                }
            }
        }
    }
}
